Skip to content

Simplify imports in SocketAddresses.swift - #3696

Open
glbrntt wants to merge 3 commits into
apple:mainfrom
glbrntt:sock-addr-imports
Open

Simplify imports in SocketAddresses.swift#3696
glbrntt wants to merge 3 commits into
apple:mainfrom
glbrntt:sock-addr-imports

Conversation

@glbrntt

@glbrntt glbrntt commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Motivation:

The module map for glibc is broken which can lead libc symbols being attributed to the wrong module. In NIO, SocketAddresses.swift imports CNIOLinux (and friends) but, as far as I can tell, doesn't use any of their symbols directly. The result is that various libc symbols incorrectly get attributed to CNIOLinux and compilation can fail for downstream packages with member import visibility checks enabled.

See also: swiftlang/swift#85427

Modifications:

  • Remove the CNIO* imports from SocketAddresses.swift as they appear to be unused
  • Simplify the imoport block

Result:

Can build grpc with member import visibility checks enabled.

Motivation:

The module map for glibc is broken which can lead libc symbols being
attributed to the wrong module. In NIO, SocketAddresses.swift imports
CNIOLinux (and friends) but, as far as I can tell, doesn't use any of
their symbols directly. The result is that various libc symbols incorrectly
get attributed to CNIOLinux and compilation can fail for downstream
packages with member import visibility checks enabled.

See also: swiftlang/swift#85427

Modifications:

- Remove the CNIO* imports from SocketAddresses.swift as they appear to
  be unused
- Simplify the imoport block

Result:

Can build grpc with member import visibility checks enabled.
@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Aug 11, 2026
@glbrntt

glbrntt commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

This is by no means a complete fix: it just unblocks the issue we're currently seeing in gRPC. I'm also a bit nervous about there being unintended consequences of this change.

This PR ran into this issue: grpc/grpc-swift-nio-transport#186

/grpc-swift-nio-transport/Sources/GRPCNIOTransportCore/Client/Resolver/DNSResolver.swift:178:84: error: property 'sin_port' is not available due to missing import of defining module 'CNIOLinux' [#MemberImportVisibility]
 23 | #elseif canImport(Glibc)
 24 | private import Glibc
 25 | #elseif canImport(Musl)
    | `- note: add import of module 'CNIOLinux'
 26 | private import Musl
 27 | #else
    :
176 |     }
177 | 
178 |     self = .init(host: presentationAddress, port: Int(in_port_t(bigEndian: address.sin_port)))
    |                                                                                    `- error: property 'sin_port' is not available due to missing import of defining module 'CNIOLinux' [#MemberImportVisibility]
179 |   }
180 | }

import CNIOFreeBSD
#elseif os(OpenBSD)
@preconcurrency import Glibc
import CNIOOpenBSD

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the CNIOOpenBSD not needed anymore? Well CI should show.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no CNIOOpenBSD_* symbols in this file which makes me think it isn't.(All symbols in the header have that prefix, see here.)

It's the same for CNIOLinux: it appears as if the import isn't necessary here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants